package fr.toto.triseries;

import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.SplashScreen;

public class MySplashScreen {

	private SplashScreen splash;
	private Graphics2D g;

	private MySplashScreen() {

	}

	public static MySplashScreen getSplashScreen() {
		MySplashScreen s = new MySplashScreen();
		s.splash = SplashScreen.getSplashScreen();
		if (s.splash == null) {
			System.out.println("SplashScreen.getSplashScreen() returned null");
		} else {
			s.g = s.splash.createGraphics();
			if (s.g == null) {
				System.out.println("g is null");
			}
		}
		return s;
	}

	public void close() {
		if (splash != null)
			splash.close();
	}

	public void displayMessage(String msg) {
		if (splash == null)
			return;
		if (splash.isVisible()) {
			renderSplashFrame(g, msg);
			splash.update();
		}
	}

	static void renderSplashFrame(Graphics2D g, String msg) {
		g.setComposite(AlphaComposite.Clear);
		g.setColor(Color.LIGHT_GRAY);
		g.fillRect(10, 280, 580, 20);
		g.setPaintMode();
		g.setColor(Color.BLACK);
		g.drawString(msg, 40, 290);
	}

}
